﻿using System;
using System.Collections.Specialized;
using System.Web;
using NetFramework;

namespace TMSPortal.UI.Resource
{
    public static class QueryStringManager
    {
        /// <summary>
        /// 
        /// </summary>
        public static NameValueCollection QueryString
        {
            get { return HttpContext.Current.Request.QueryString; }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetValue(string key)
        {
            return GetValue<string>(key, string.Empty);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <returns></returns>
        public static T GetValue<T>(string key)
        {
            return GetValue<T>(key, default(T));
        }

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="defaultValue"></param>
        /// <returns></returns>
        public static T GetValue<T>(string key, T defaultValue)
        {
            string value = QueryString[key];
            if (string.IsNullOrEmpty(value))
            {
                return defaultValue;
            }
            
            return Converter.ToType<T>(value);
        }
    }
}
